﻿using System;
using System.Threading;
using System.Windows.Input;

using MvvmFoundation.Wpf;

namespace Zuehlke.Blueprint.Quickstart.Architecture.Presentation.UserInterface.Views
{
    /// <summary>
    /// ViewModel for the taksbar view.
    /// </summary>
    public class AboutViewModel
    {
        public AboutViewModel()
        {
            ThrowUiExceptionCommand = new RelayCommand(ThrowUiException);
            ThrowBackgroundExceptionCommand = new RelayCommand(ThrowBackgroundException);
        }

        public ICommand ThrowUiExceptionCommand { get; private set; }

        public ICommand ThrowBackgroundExceptionCommand { get; private set; }

        private void ThrowUiException()
        {
            throw new ApplicationException("UI thread exception", new InvalidOperationException("Not allowed to break here!"));
        }

        private void ThrowBackgroundException()
        {
            var exception = new ApplicationException("UI thread exception", new InvalidOperationException("Not allowed to break here!"));
            new Thread(ThrowDomainException).Start(exception);
        }

        private static void ThrowDomainException(object e)
        {
            var exception = e as ApplicationException;
            if (exception == null)
            {
                throw new ArgumentNullException("e");
            }

            throw exception;
        }
    }
}
